package com.example.tnot.Teacher.MinePart.InternalFragment;

import android.os.Bundle;

import androidx.activity.OnBackPressedCallback;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.example.tnot.R;
import com.example.tnot.Teacher.ActivityConfig.TeacherHomeActivity;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.login.MainActivity;

public class personalFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private OnBackPressedCallback onBackPressedCallback;
    private String mParam1;
    private String mParam2;

    ImageButton btn_back;
    public personalFragment() {
        // Required empty public constructor
    }
    public static personalFragment newInstance(String param1, String param2) {
        personalFragment fragment = new personalFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onBackPressedCallback = new OnBackPressedCallback(true) {
            @Override
            public void handleOnBackPressed() {
                // 处理返回键事件
                handleBackPressed();
            }
        };
        requireActivity().getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mine_personal_fragment, container, false);
        btn_back = view.findViewById(R.id.ib_personal_back);

        btn_back.setOnClickListener(new View.OnClickListener() {
            //点击返回按钮
            @Override
            public void onClick(View v) {
                //处理返回按钮事件
                handleBackPressed();
            }
        });
        return view;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        // 移除回调，避免内存泄漏
        if (onBackPressedCallback != null) {
            onBackPressedCallback.remove();
        }
    }
}